package ro.imc.rest.client.display;

import ro.imc.rest.client.display.util.RootPanelDivId;
import ro.imc.rest.client.display.util.RootPanelManager;
import ro.imc.rest.shared.dto.RestLogin;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.ToggleButton;

public class TopBarForm extends Composite {

	private static TopBarFormUiBinder uiBinder = GWT
			.create(TopBarFormUiBinder.class);
	@UiField Label strUser;
	@UiField Image image;
	@UiField static ToggleButton useJersey;
	@UiField static ToggleButton useGWTserver;
	@UiField static ToggleButton useGWTclient;
	
	private RestLogin user;
	interface TopBarFormUiBinder extends UiBinder<Widget, TopBarForm> {
	}

	public TopBarForm(RestLogin user) {
		this.user = user;
		initWidget(uiBinder.createAndBindUi(this));
		fillTopBarSettings();
		useGWTserver.setDown(true);
	}


	@UiHandler("image")
	void onImageClick(ClickEvent event) {
		RootPanelManager.clearUi();
		RootPanelManager.attachForm(RootPanelDivId.LOGIN_FORM_ID, new LoginBoxForm());
	}
	
	private void fillTopBarSettings () {
		strUser.setText(user.getName());
	}
	@UiHandler("useGWTserver")
	void onUseGWTserverClick(ClickEvent event) {
		useGWTserver.setDown(true);
		useGWTclient.setDown(false);
		useJersey.setDown(false);
		ScreenForm.logArea.setText(ScreenForm.logArea.getText() + "\nUsing GWT Server - Side to make REST Request");
		
	}
	@UiHandler("useGWTclient")
	void onUseGWTclientClick(ClickEvent event) {
		useGWTserver.setDown(false);
		useGWTclient.setDown(true);
		useJersey.setDown(false);
		ScreenForm.logArea.setText(ScreenForm.logArea.getText() + "\nUsing GWT Client - Side to make REST Request");
	}
	@UiHandler("useJersey")
	void onUseJersetClick(ClickEvent event) {
		useGWTserver.setDown(false);
		useGWTclient.setDown(false);
		useJersey.setDown(true);
		ScreenForm.logArea.setText(ScreenForm.logArea.getText() + "\nUsing GWT Server - Side with Jersey to make REST Request");
	}
}
